﻿<?php
/**
 * @package		Joomla.Site
 * @subpackage	com_content
 * @copyright	Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// no direct access
defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_COMPONENT.'/helpers');
$app = & JFactory::getApplication();
$templatepath = JURI::base() . 'templates/' . $app->getTemplate();
$db =& JFactory::getDBO();
$lang =& JFactory::getLanguage()->getTag();
?>
<div id="k2Container" class="itemListView blog">
	<div class="componentheading blog">
		<h2><?php echo $this->escape($this->params->get('page_heading')); ?></h2>
	</div>	
	<div class="itemList">
		<?php if(empty($this->items)) :?>
			<div>
				<img src="images/underconstruction.png">
			</div>
		<?php else: ?>
		<div id="itemListLeading">
		
			<?php foreach ($this->items as $key => &$item) : ?>
			<?php //var_dump($item);die; ?>
			<?php $author =  $item->author; ?>
			<?php $author = ($item->created_by_alias ? $item->created_by_alias : $author);?>
			<?php $catid =$item->catid; ?>
			<?php $link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $catid)); ?>
			<?php
				$images = json_decode($item->images);
				$image = is_file($images->image_intro)?$images->image_intro:$templatepath.'/src/images/no-image.gif';
				$query = "SELECT count(*) num_comments FROM #__jcomments where object_id = ".$db->Quote($item->id)." and object_group=".$db->Quote('com_content')." AND lang =".$db->Quote($lang)." AND published =".$db->Quote(1);
				//echo $query;die;
				$db->setQuery( $query );
				$num_comments = $db->loadObject()->num_comments;
			?>
			<div class="K2ItemsRow K2Row-<?php echo $key; ?>">
				<div class="itemContainer itemContainerLast" style="width:100.0%;">
					<div class="catItemView groupLeading blog">
						<span class="catItemDateCreated"><strong><?php echo JHtml::date($item->created , 'd');?></strong><?php echo JHtml::date($item->created , 'F');?></span>
						<div class="catItemHeader">
							<h3 class="catItemTitle">
								<a href="<?php echo $link; ?>">
									<?php echo JHtml::_('string.truncate', $item->title, 55); ?></a>
							</h3>
							<?php if($num_comments): ?>
							<div class="catItemCommentsLink">
								<a href="<?php echo  $link.'#itemCommentsAnchor'; ?>"><?php echo $num_comments; ?></a>
							</div>
							<?php endif; ?>
							<span class="catItemAuthor">
								<?php echo JText::_('COM_CONTENT_WRITTEN_BY'); ?>
								<a rel="author" href="#">
								<?php echo $author; ?></a>
							</span>
						</div>
						<div class="catItemBody">
							<div class="catItemImageBlock">
								<span class="catItemImage">
									<a href="<?php echo $link; ?>" title="<?php echo $item->title; ?>"><span class="before"></span>
										<img src="timthumb.php?src=<?php echo $image;?>&w=586&h=238" alt="<?php echo $item->title; ?>">
									</a>
								</span>
								<div class="clr"></div>
							</div>
							<div class="catItemIntroText">
								<p>	<?php echo JHtml::_('string.truncate', strip_tags($item->introtext), 250); ?></p>
								<div class="catItemReadMore">
								<a class="k2ReadMore" href="<?php echo $link; ?>"><span class="before"></span>
								<?php echo JText::_('COM_CONTENT_READ_MORE'); ?></a>
								</div>
							</div>
							<div class="clr"></div>
							<div class="clr"></div>
						</div>
						<div class="clr"></div>
						<div class="clr"></div>
						<div class="clr"></div>
					</div>
					<div class="clr"></div>
				</div>
				<div class="clr"></div>
			</div>
			<?php endforeach; ?>
		</div>
		<?php endif; ?>
		<div class="clr"></div>
		<div class="clr"></div>
	</div>
	<div class="k2Pagination">
		<div class="clr"></div>
		<?php echo $this->pagination->getPagesLinks(); ?>
	</div>
</div>


<?php return; ?>
<div class="category-list<?php echo $this->pageclass_sfx;?>">

	<?php if ($this->params->get('show_page_heading')) : ?>
	<h1>
		<?php echo $this->escape($this->params->get('page_heading')); ?>
	</h1>
	<?php endif; ?>

	<?php if ($this->params->get('show_category_title', 1) or $this->params->get('page_subheading')) : ?>
	<h2>
		<?php echo $this->escape($this->params->get('page_subheading')); ?>
		<?php if ($this->params->get('show_category_title')) : ?>
			<span class="subheading-category"><?php echo $this->category->title;?></span>
		<?php endif; ?>
	</h2>
	<?php endif; ?>

	<?php if ($this->params->get('show_description', 1) || $this->params->def('show_description_image', 1)) : ?>
	<div class="category-desc">
		<?php if ($this->params->get('show_description_image') && $this->category->getParams()->get('image')) : ?>
			<img src="<?php echo $this->category->getParams()->get('image'); ?>"/>
		<?php endif; ?>
		<?php if ($this->params->get('show_description') && $this->category->description) : ?>
			<?php echo JHtml::_('content.prepare', $this->category->description, '', 'com_content.category'); ?>
		<?php endif; ?>
		<div class="clr"></div>
	</div>
	<?php endif; ?>

	<div class="cat-items">
		<?php echo $this->loadTemplate('articles'); ?>
	</div>

	<?php if (!empty($this->children[$this->category->id])&& $this->maxLevel != 0) : ?>
	<div class="cat-children">
		<h3>
			<?php echo JTEXT::_('JGLOBAL_SUBCATEGORIES'); ?>
		</h3>

		<?php echo $this->loadTemplate('children'); ?>
	</div>
	<?php endif; ?>
</div>
